/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.mamesoft.namibiamc.beans;

import com.mamesoft.namibiamc.tools.JDBC;
import com.mysql.jdbc.Connection;
import java.io.Serializable;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author simone
 */
public class ModifyPasswordBean implements Serializable {

    private LoginBean loginBean;
    private String email;
    private String password;
    private boolean emailError;
    private boolean emailSuccess;
    private boolean passError;
    private boolean passSuccess;

    /** Creates a new instance of ModifyPasswordBean */
    public ModifyPasswordBean() {
    }

    public void emailAction() {
        Connection c = null; 
        try {
            c = JDBC.connect();
            String q = "UPDATE " + getLoginBean().getRole() + " SET email = '" + getEmail() + "' WHERE id ='" + getLoginBean().getId() + "'";
            JDBC.executeStatement(q, c);
            emailSuccess = true;
        } catch (Exception ex) {
            emailError = true;
        } finally{
            if (c != null){
                try {
                    c.close();
                } catch (SQLException ex) {
                    Logger.getLogger(ModifyPasswordBean.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        }
    }
    
    public void passAction() {
        Connection c = null; 
        try {
            c = JDBC.connect();
            String q = "UPDATE " + getLoginBean().getRole() + " SET password = '" + getPassword() + "' WHERE id ='" + getLoginBean().getId() + "'";
            JDBC.executeStatement(q, c);
            passSuccess = true;
        } catch (Exception ex) {
            passError = true;
        } finally{
            if (c != null){
                try {
                    c.close();
                } catch (SQLException ex) {
                    Logger.getLogger(ModifyPasswordBean.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        }
    }

    /**
     * @return the email
     */
    public String getEmail() {
        return email;
    }

    /**
     * @param email the email to set
     */
    public void setEmail(String email) {
        this.email = email;
    }

    /**
     * @return the password
     */
    public String getPassword() {
        return password;
    }

    /**
     * @param password the password to set
     */
    public void setPassword(String password) {
        this.password = password;
    }

    /**
     * @return the loginBean
     */
    public LoginBean getLoginBean() {
        return loginBean;
    }

    /**
     * @param loginBean the loginBean to set
     */
    public void setLoginBean(LoginBean loginBean) {
        this.loginBean = loginBean;
    }

    /**
     * @return the emailError
     */
    public boolean isEmailError() {
        return emailError;
    }

    /**
     * @param emailError the emailError to set
     */
    public void setEmailError(boolean emailError) {
        this.emailError = emailError;
    }

    /**
     * @return the emailSuccess
     */
    public boolean isEmailSuccess() {
        return emailSuccess;
    }

    /**
     * @param emailSuccess the emailSuccess to set
     */
    public void setEmailSuccess(boolean emailSuccess) {
        this.emailSuccess = emailSuccess;
    }

    /**
     * @return the passError
     */
    public boolean isPassError() {
        return passError;
    }

    /**
     * @param passError the passError to set
     */
    public void setPassError(boolean passError) {
        this.passError = passError;
    }

    /**
     * @return the passSuccess
     */
    public boolean isPassSuccess() {
        return passSuccess;
    }

    /**
     * @param passSuccess the passSuccess to set
     */
    public void setPassSuccess(boolean passSuccess) {
        this.passSuccess = passSuccess;
    }
}
